package org.yeruyi.outside.picasso;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.graphics.RectF;

import com.squareup.picasso.Transformation;


/**
 * Author:Yeruyi
 * Date:2017/12/05
 * Version:v1.0
 * Scope:
 * 2017年12月05日 Picasso图片方形加载库
 */

public class CropSquareTransformation implements Transformation {

    @Override
    public Bitmap transform(Bitmap source) {
        int size=Math.min(source.getWidth(),source.getHeight());
        int x=(source.getWidth()-size)/2;
        int y=(source.getHeight()-size)/2;
        Bitmap result=Bitmap.createBitmap(source,x,y,size,size);
        if (result!=source){
            source.recycle();//释放bitmap
        }
        return result;
    }

    @Override public String key() { return "square()"; }
}